package cn.com.recode.重构方法.有局部变量.只读不修改;

import cn.com.recode.重构方法.无局部变量.Order;

import java.util.Enumeration;
import java.util.Vector;

public class A {

    private String name;

    private int amout;

    private Vector orders = new Vector<Order>();

    void printOwing() {

        printBanner();
        double outstanding = getOutstanding();

        //print details
        printDetails(outstanding);
    }

    /**
     * 被目标函数复制并且接下来的函数仍然使用了这个 变量
     * @return
     */
    private double getOutstanding() {
        Enumeration elements = orders.elements();
        double outstanding = 0.0;
        while (elements.hasMoreElements()) {
            Order order = (Order)elements.nextElement();
            outstanding += order.getAmout();
        }
        return outstanding;
    }

    /**
     * 局部变量只读不修改
     * @param outstanding
     */
    private void printDetails(double outstanding) {
        System.out.println("name:"+name);
        System.out.println("amout:"+outstanding);
    }

    private void printBanner() {
        System.out.println("***************************");
        System.out.println("********** *Customer Owes* *********");
        System.out.println("***************************");
    }
}
